﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Microsoft.SharePoint.Administration;
using System.Windows;

namespace SharePointCommander.Model.TreeView
{
    public class SCWebService : SCTreeViewItem<SPWebService>
    {
        public SCWebService(SCTreeViewItem parent, SPWebService webService)
            : base(parent, webService)
        {
            Header = webService.TypeName;
            IsExpanded = false;
            Expanded += new RoutedEventHandler(SCWebService_Expanded);
            ItemsSource = new object[] { null };
        }

        void SCWebService_Expanded(object sender, System.Windows.RoutedEventArgs e)
        {
            TreeViewItem item = e.Source as TreeViewItem;
            if (item.ItemsSource.Cast<object>().Contains(null))
            {
                item.ItemsSource = (from s in SPObject.WebApplications select new SCWebApplication(this, s) as TreeViewItem)
                    .Union(
                        new[] { new SCProperties(this, SPObject.Properties) }
                    );
            }
        }
    }
}
